<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>学生信息</title>

		<meta name="description" content="Static &amp; Dynamic Tables" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

		<!-- bootstrap & fontawesome -->
		
	</head>

	<body class="no-skin">
		<!-- #section:basics/navbar.layout -->
		

		<!-- /section:basics/navbar.layout -->
		<div class="main-container" id="main-container">
			

			<!-- #section:basics/sidebar -->
			

			<!-- /section:basics/sidebar -->
			<div class="main-content">
				<!-- #section:basics/content.breadcrumbs -->
				

				<!-- /section:basics/content.breadcrumbs -->
				<div class="page-content">
					<!-- #section:settings.box -->
					

					<!-- /section:settings.box -->
					<div class="page-content-area">
						<div class="page-header">
							<h1>
								Tables
								<small>
									<i class="ace-icon fa fa-angle-double-right"></i>
									Static &amp; Dynamic Tables
								</small>
							</h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div class="row">
									<div class="col-xs-12">
										<table id="sample-table-1" class="table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th class="center"><a href="subAdd"><spring:message code="page.index.add"/></a></th>
													<th><a href="subChangeLocale?localeType=en_US"><spring:message code="page.index.english"/></a></th>
													<th><a href="subChangeLocale?localeType=zh_CN"><spring:message code="page.index.chinese"/></a></th>
													<th class="hidden-480"></th>
													<th class="hidden-480"></th>
													<th class="hidden-480"></th>
													<th class="hidden-480"></th>
													<th class="hidden-480"></th>
													<th></th>
													<th class="hidden-480"></th>
												</tr>
											</thead>
											<thead>
												<tr>
													<th class="center">
														<label class="position-relative">
															<input type="checkbox" class="ace" />
															<span class="lbl"></span>
														</label>
													</th>

													<th><spring:message code="page.index.subId"/></th>
													<th><spring:message code="page.index.subName"/></th>
													<th><spring:message code="page.index.description"/></th>
													<th><spring:message code="page.index.testCount"/></th>
													<th><spring:message code="page.index.totalTime"/></th>
													<th><spring:message code="page.index.totalScore"/></th>
													<th><spring:message code="page.index.status"/></th>
													<th>管理科目学生</th>
													<th class="hidden-480"><spring:message code="user.action.message"/></th>
												</tr>
											</thead>

											<tbody>
												<c:forEach items="${page.dates }" var="examSubject">
													<tr>
														<td class="center">
															<label class="position-relative">
																<input type="checkbox" class="ace" />
																<span class="lbl"></span>
															</label>
														</td>
														<td>${examSubject.subId }</td>
														<td>${examSubject.name }</td>
														<td>${examSubject.description }</td>
														<td>${examSubject.testCount }</td>
														<td>${examSubject.totalTime }</td>
														<td>${examSubject.totalScore }</td>
														<td>
															<c:choose>
																<c:when test="${examSubject.status == 0 }">
																	<input name="switch-field-1" value="${examSubject.subId }" class="ace ace-switch ace-switch-6 subject-atatus" type="checkbox">
																	<span class="lbl"></span>
																</c:when>
																<c:otherwise>
																	<input name="switch-field-1" value="${examSubject.subId }" checked class="ace ace-switch ace-switch-6 subject-atatus" type="checkbox">
																	<span class="lbl"></span>
																</c:otherwise>
															</c:choose>
														</td>
														<td>
															<c:choose>
																<c:when test="${examSubject.status == 0 }">
																	<a title="管理科目学生" disabled="disabled" class="btn btn-primary btn-xs manage-subject-student-btn">
																			<i class="ace-icon fa fa-pencil"></i>
																	</a>
																</c:when>
																<c:otherwise>	
																	<a title="管理科目学生" class="btn btn-primary btn-xs manage-subject-student-btn">
																			<i class="ace-icon fa fa-pencil"></i>
																	</a>
																</c:otherwise>
															</c:choose>
														</td>
														<td>
															<a href="subEdit/${examSubject.subId }"><spring:message code="page.index.edit"/></a> 
															<a class="delete" href="subDelete/${examSubject.subId }"><spring:message code="page.index.delete"/></a>
															
														</td>
														
													</tr>
												</c:forEach>
												
											</tbody>
										</table>
									</div><!-- /.span -->
								</div><!-- /.row -->
								<!-- 模态框 -->
								<div class="modal fade" id="subjectStudentModal" tabindex="-1" role="dialog" aria-labelledby="subjectStudentModal" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
													&times;
												</button>
												<h4 class="modal-title" id="addTestModalLabel">
													管理学生科目：<label id="modalSubjectName"></label>
												</h4>
											</div>
											<div class="modal-body">
												<input type="hidden" id="subjectId"/>
												<div id="subjectStudentContent" class="control-group">
													
												</div>
											</div>
											
											<div class="modal-footer">
													<button type="button" class="btn btn-default" data-dismiss="modal">关闭
													</button>
													<button id="subjectStudentSaveBtn" type="button" class="btn btn-primary">
														保存
													</button>
											</div>
											
										</div><!-- /.modal-content -->
									</div><!-- /.modal -->
								</div>
								
								
								<script type="text/javascript">
									$(function(){
										$(".delete").click(function(){
											if(confirm("是否确认删除？")){
												return true;
											}else{
												return false;
											}
										})
									})
								</script>
								
								<script type="text/javascript">
								
								
								$(function(){
									$(".subject-atatus").click(function(){
										var subId = $(this).val();
										$.ajax({
											type: 'post',
											url: '${contestPath}/OnlineExam/subEditStatus',
											data:{
												subId: subId
											},
											dataType: "json",
											success: function(data){
												
											}
										})
										
										//window.location.reload();
										
									});
									
									//弹出模态框
									$(".manage-subject-student-btn").click(function(){
										var subId = $(this).parent().siblings().eq(1).text();
										$.ajax({
											type:'post',
											url:'${contestPath}/OnlineExam/getAllStudent',
											data:{
												subId:subId
											},
											dataType: "json",
											success: function(data){
												
												var htmlString = '';
												var selectedUser = data.selectedUser;
												var score = data.score;
												for(var i = 0; i < data.allUser.length; i++){
													var user = data.allUser[i];
													var checked = checkSelectedUser(selectedUser, user.userId) ? 'checked="checked"' : '';
													var checkIsOk = checkSelectedIsOk(score, user.userId) ? 'disabled="disabled"' : '';
													htmlString += '<div class="checkbox">';
													htmlString += '		<label>';
													htmlString += '			<input name="subjectStudents" class="ace ace-checkbox-2" type="checkbox" value="'
																			+ user.userId + '" ' + checked +' ' +checkIsOk+' />';
													htmlString += '			<span class="lbl">' + user.userName + '</span>';
													htmlString += '		</label>';
													htmlString += '</div>';
													
												}
												$('#subjectStudentContent').html(htmlString);
												$('#subjectId').val(subId);
											}
										});
										$('#modalSubjectName').text($(this).parents("td").siblings("td").eq(1).text());
										$('#subjectStudentModal').modal('show');
									});
									
									var checkSelectedUser = function(selectedUser, userId){
										for(i=0; i<=selectedUser.length;i++){
											var user =  selectedUser[i];
											if(user == userId){
												return true;
											}
										}
										return false;
									}
									
							 		var checkSelectedIsOk =  function(score, userId){
										for(i=0; i<score.length;i++){
											var user =  score[i];
											if(user.userId == userId){
												return true;
											}
										}
										return false;
									} 
									
									//保存
									$('#subjectStudentSaveBtn').on('click', function(){
										var subjectStudents = [];
										for(var i = 0; i<$('input[name="subjectStudents"]:checked').length; i++){
											subjectStudents[i] = $($('input[name="subjectStudents"]:checked')[i]).val();
										}
										$.ajax({
											type: 'POST',
											url: '${contestPath}/OnlineExam/saveSubjectStudents',
											data: {
												subjectStudents: subjectStudents,
												subjectId: $('#subjectId').val()
											},
											dataType: "json",
											success: function(data){
												if(data.success){
													alert("成功");
													$("#subjectStudentModal").modal('hide');
												}else{
													alert("失败");
												}
											}
										})
									})
									
									
								})
								
								</script>

								<div id="modal-table" class="modal fade" tabindex="-1">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header no-padding">
												<div class="table-header">
													<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
														<span class="white">&times;</span>
													</button>
													Results for "Latest Registered Domains
												</div>
											</div>

											

											
										</div><!-- /.modal-content -->
									</div><!-- /.modal-dialog -->
								</div><!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content-area -->
				</div><!-- /.page-content -->
			</div><!-- /.main-content -->

			

			
		</div><!-- /.main-container -->

		<!-- basic scripts -->

		<!--[if !IE]> -->
	

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='${pageContext.request.contextPath }/static/assets/js/jquery1x.min.js'>"+"<"+"/script>");
</script>
<![endif]-->
		
	</body>
</html>
